package bussiness.user;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import database.dao.UserDao;

/**
 * Servlet implementation class UsrIsValid
 */
public class QueryValid extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public QueryValid() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		PrintWriter out = response.getWriter();
		String type = request.getParameter("type");
		String param = request.getParameter("param");
		boolean ret;
		if(type.equals("username")) {
			ret = UserDao.userNameValid(param);
		}
		else {
			ret = UserDao.emailValid(param);
		}
		if(ret) {
			out.print("Y");
		}
		else {
			out.print("N");
		}
		out.flush();
	}
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doPost(request, response);
	}
}
